<?php
/**
 * Abstract class for plugins type of <i>Psa_Plugin_View</i>.
 * 
 * LICENSE:
 * 
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with This library. If not, see <{@link http://www.gnu.org/licenses/}>.
 *
 * @link http://code.google.com/p/phpstartapp/
 * @author Bojan Mauser <bmauser@gmail.com>
 * @copyright Bojan Mauser 2009
 * @package psa
 * @subpackage plugins
 * @version $Id: Psa_Plugin_View.class.php 464 2009-03-24 00:30:12Z bmauser $
 */


/**
 * Abstract class for plugins type of <i>Psa_Plugin_View</i>.
 * View plugins (classes that extends Psa_Plugin_View class) are place for for methods that will
 * generate and display result from your application. This can be HTML, XML or something else.
 * View methods, like model methods, are called from controller. All application logic should 
 * be in model and in view you should put only part for displaying results like template rendering code. 
 * 
 * You can organize your view methods into more view classes to be logically grouped.
 * 
 * You can write <i>Psa_Plugin_View</i> plugins by extending this class. Here is an example:
 * 
 * <code>
 * <?php
 * class example_view extends Psa_Plugin_View{
 * 
 * 	// Render even_numbers.tpl template and put it in "result" smarty value	
 * 	function even_numbers(){
 * 		$rendered_result = $this->psa_smarty->fetch("example_app/even_numbers.tpl");
 * 		$this->psa_smarty->assign("result", $rendered_result);
 * 	}	
 * 
 * 	// Main template render and display method.
 * 	// Every application should have one method like this for one controller.
 * 	// This method should determine if request is made by ajax or not and echo only
 * 	// ajax result or whole html page.
 * 	function generate_html(){
 * 		
 * 		$rendered_menu = $this->psa_smarty->fetch("example_app/menu.tpl");
 * 		$rendered_header = $this->psa_smarty->fetch("example_app/header.tpl");
 * 		
 * 		$this->psa_smarty->assign("header", $rendered_header);
 * 		$this->psa_smarty->assign("menu", $rendered_menu);
 * 		
 * 		echo $this->psa_smarty->fetch("example_app/main.tpl");
 * 	}
 * }
 * ?>
 * </code>
 * 
 * @see Psa_Plugin_Controller
 * @see Psa_Plugin_Model
 */
abstract class Psa_Plugin_View{
	
	/**
	 * Reference to result object
	 * @var Psa_Result
	 */
	public $psa_result;

	
	/**
	 * Reference to Smarty template engine object.
	 * It is set if Smarty object is instanced by psa_use_smarty() method in controller plugin before
	 * calling view plugins.
	 * @var Psa_Smarty
	 * @see psa_use_smarty()
	 */
	public $psa_smarty;
	
	
	/**
	 * Reference to Dully template engine object.
	 * It is set if Dully object is instanced by psa_use_dully() method in controller plugin before
	 * calling view plugins.
	 * @var Psa_Dully
	 * @see psa_use_dully()
	 * @see Psa_Dully.class.php
	 */
	public $psa_dully;
	
	
	/**
	 * Reference to registry object
	 * @var Psa_Registry
	 */
	public $psa_registry;
	
	
	/**
	 * Constructor. Sets some object references.
	 */
	function __construct(){
		
		// set reference to $psa_result object
		$this->psa_result = Psa_Result::get_instance();
		
		// set reference to registry object
		$this->psa_registry = Psa_Registry::get_instance();
		
		// set reference to $psa_smarty object if exists
		if(isset(Psa_Registry::get_instance()->psa_smarty))
			$this->psa_smarty = Psa_Registry::get_instance()->psa_smarty;
		
		// set reference to $Psa_Dully object if exists
		if(isset(Psa_Registry::get_instance()->psa_dully))
			$this->psa_dully = Psa_Registry::get_instance()->psa_dully;
	}
}

